import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class p1706 {
    static List<Integer> path = new ArrayList<>();
    static boolean[] check = new boolean[10];
    public static void main(String[] args) throws IOException {
        PrintWriter p = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        StreamTokenizer sc = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        //独木桥的长度
        sc.nextToken();
        int n = (int)sc.nval;
        sc.nextToken();
        int k = (int)sc.nval;
        f(0, n, k);
    }
    static void f(int index, int n, int k){
        if(index == k){
            for(int i : path){
                System.out.print(i + " ");
            }
            System.out.println();
            return;
        }
        for(int i = 1; i <= n; i++){
            if(!check[i]){
                check[i] = true;
                path.add(i);
                f(index + 1, n, k);
                check[i] = false;
                path.remove(path.size() - 1);
            }
        }
    }
}
